﻿using DFGK_WMS.IRepository;
using DFGK_WMS.Model.DTO;
using DFGK_WMS.Model.Models;
using DFGK_WMS.Repository;
using DFGK_WMS.WebAPI.Controllers.Result;
using Microsoft.AspNetCore.Mvc;

namespace DFGJ.WMS_PDA.WebAPI.Controllers.PDA
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BindPickingPositionContriller : Controller
    {
        private IBindPickingPositionRepository bindPickingPositionRepository;
        public BindPickingPositionContriller(IBindPickingPositionRepository BindPickingPositionRepository)
        {
            bindPickingPositionRepository = BindPickingPositionRepository;
        }

        /// <summary>
        /// 绑定拣选位
        /// </summary>
        /// <param name="pickingPosition"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddBindPickingPosition(BindPickingPositionModel pickingPosition)
        {
            string msg = "";
            if (pickingPosition == null)
            {
                return Ok(BaseResult.Result(false, "请求参数为空", "500"));
            }
            var IsOk = bindPickingPositionRepository.AddBindPickingPosition(pickingPosition, out msg);
            if (IsOk)
            {
                return Ok(BaseResult.Result(true, "添加成功", "200"));
            }
            return Ok(BaseResult.Result(false, msg, "500"));
        }


        /// <summary>
        /// 解除拣选位
        /// </summary>
        /// <param name="pickingPosition"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult DelBindPickingPosition(BindPickingPositionModel dto)
        {
            string msg = "";
            if (dto == null)
            {
                return Ok(BaseResult.Result(false, "请求参数为空", "500"));
            }
            var IsOk = bindPickingPositionRepository.DelBindPickingPosition(dto, out msg);
            if (IsOk)
            {
                return Ok(BaseResult.Result(true, "解除成功", "200"));
            }
            return Ok(BaseResult.Result(false, msg, "500"));
        }

        /// <summary>
        /// 获取所有拣选位
        /// </summary>
        /// <param name="pickingPosition"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetBindPickingPosition()
        {

            var list = bindPickingPositionRepository.GetBindPickingPosition();
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "查询成功", "200"));
            }
            return Ok(BaseResult.Result(false, "查询失败", "500"));
        }
    }
}
